//package com.nowcoder.community.event;
//
//import com.alibaba.fastjson.JSONObject;
//import com.nowcoder.community.entity.Event;
//import com.nowcoder.community.entity.Message;
//import com.nowcoder.community.service.MessageService;
//import com.nowcoder.community.util.CommunityConstant;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author tang
// * @create 2020-11-09
// */
//@Deprecated
//@Component
//public class EventConsumer implements CommunityConstant {
//    private static final Logger logger = LoggerFactory.getLogger(EventConsumer.class);
//
//    @Autowired
//    private MessageService messageService;
//
//    @KafkaListener(topics = {TOPIC_LIKE})
//    public void handleCommmentMessage(ConsumerRecord record){
//        if (record==null||record.value()==null){
//            logger.error("the message is empty");
//            return;
//        }
//
//        Event event = JSONObject.parseObject(record.value().toString(),Event.class);
//        if (event == null){
//            logger.error("the form is wrong");
//            return;
//        }
//
//        Message message = new Message();
//        message.setFromId(SYSTEM_ID);
//        message.setToId(event.getEntityUserId());
//        message.setConversationId(event.getTopic());
//        message.setCreateTime(new Date());
//
//        Map<String,Object> content = new HashMap<>();
//        content.put("userId",event.getUserId());
//        content.put("entityType",event.getEntityType());
//        content.put("entityId",event.getEntityId());
//
//        if (!event.getData().isEmpty()) {
//            for (Map.Entry<String,Object> entry:event.getData().entrySet()){
//                content.put(entry.getKey(),entry.getValue());
//            }
//        }
//
//        message.setContent(JSONObject.toJSONString(content));
//        messageService.addMessage(message);
//
//    }
//
//}
